package org.qengine.service;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.qengine.dao.DicTypeDao;
import org.qengine.entity.DicTypeEntity;
import org.springframework.stereotype.Service;

import java.util.List;

@Service("dicTypeService")
public class DicTypeServiceImpl extends ServiceImpl<DicTypeDao, DicTypeEntity> implements DicTypeService{

    @Override
    public Integer add(DicTypeEntity dicTypeEntity){
        return baseMapper.insert(dicTypeEntity);
    }

    @Override
    public Integer delete(Long id) {
        return baseMapper.deleteById(id);
    }

    @Override
    public Integer update(DicTypeEntity dicTypeEntity) {
        return baseMapper.updateById(dicTypeEntity);
    }

    @Override
    public DicTypeEntity queryByTypeName(DicTypeEntity dicTypeEntity) {
        try {
            String typeName = dicTypeEntity.getTypeName();
            // 使用 QueryWrapper 构建查询条件
            QueryWrapper<DicTypeEntity> queryWrapper = new QueryWrapper<>();
            if (typeName != null && !typeName.isEmpty()) {
                queryWrapper.eq("typeName", typeName); //
            }

            // 执行查询操作
            return baseMapper.selectOne(queryWrapper);
        } catch (Exception e) {
            // 处理异常，例如日志记录或抛出自定义异常
            e.printStackTrace();
            throw new RuntimeException("An error occurred during query: " + e.getMessage());
        }
    }

}
